package com.imooc.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA.
 *
 * @auther Levi
 * @Date: 2021/03/20/20:58
 * @Description:    如果前端重新打开一个页面没有携带cookie的话需要后端获取
 */
public class AdminCookieTokenInterceptor extends BaseInterceptor implements HandlerInterceptor {
    /**
     * 在家进入Controller之前调用
     *
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String atoken = getCookie(ADMIN_COOKIE_TOKEN, request);
        String aid = getCookie(ADMIN_COOKIE_ID, request);
        boolean run = verifyUserIdToken(aid, atoken, REDIS_ADMIN_TOKEN);
        return run;
    }
}
